import listStatus from './way-list-status.js';
import printTool from '@/pages/mine/print/util/printTool.js';
export default {
	data() {
		return {
			isHeaderShow: false,
			statusShow1: false,
			statusShow2: false,
			emptyType: 'order',
			emptyShow: false,
			pagenum: 1,
			pagesize: 10,
			searchData:{
				waybill_sn:'',
				status:'',
				status_p2:'',
				status_name:'',
				status_p2_name:'',
				createtime_start:'',
				createtime_end:'',
				send_username:'',
				send_mobile:'',
				take_username:'',
				take_mobile:'',
			},
			downOption: {
				auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
			},
			upOption: {
				auto: false, // 不自动加载 
				noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
				empty: {
					tip: '~ 暂无订单 ~', // 提示
					btnText: '去逛逛'
				}
			},
			categoryId: '',
			orderList: [], //列表数据
			canIUseGetUserProfile: false,
			ewmimage: '',
			value: ['0'],
			accordionVal: '1',
			content: '折叠内容主体，可自定义内容及样式，点击按钮修改内容使高度发生变化。',
			extraIcon: {
				color: '#4cd964',
				size: '26',
				type: 'image'
			},
			status_value1: '',
			status_value2: '',
			status_name1: '',
			status_name2: '',
			statusOptions: [
				[{
						value: '',
						text: '全部'
					},
					{
						value: 300,
						text: '待装车'
					},
					{
						value: 400,
						text: '已发车'
					},
					{
						value: 500,
						text: '已达到分拨中心'
					},
					{
						value: 600,
						text: '分拨中心已分拨'
					},
					{
						value: 650,
						text: '已到达末端网点'
					},
					{
						value: 700,
						text: '客户已签收'
					}
				]
			],
			status2Options: [
				[{
						value: '',
						text: '全部'
					},
					{
						value: 100,
						text: '待装车'
					},
					{
						value: 200,
						text: '已发车'
					},
					{
						value: 300,
						text: '已到达一级网点'
					},
					{
						value: 400,
						text: '一级网点已发出'
					},
					{
						value: 500,
						text: '分拨中心已到达'
					},
					{
						value: 600,
						text: '分拨中心已分拨'
					},
					{
						value: 650,
						text: '已到达末端网点'
					},
					{
						value: 700,
						text: '客户已签收'
					}
				]
			],
		};
	},
	props: {
		i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
		index: {
			// 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			type: Number,
			default () {
				return 0;
			}
		},
		listTop: {
			type: Number,
			default () {
				return 10;
			}
		},
		skeyword: {
			type: String,
			default () {
				return '';
			}
		},
		tabObj: {
			type: Object,
			default () {
				return;
			}
		}
	},
	watch: {
		skeyword(newVal, oldVal) {
			if (newVal) {
				// this.mescroll.resetUpScroll()
			}
		}
	},
	created() {
		//加判断 编辑页来的，请求列表接口

		// #ifdef MP-WEIXIN
		if (wx.getUserProfile) this.canIUseGetUserProfile = true;
		// #endif
	},
	onShow() {
		if (!this.check.isLogin()) {
			uni.navigateTo({
				url: "/pages/login/login/login"
			});
		} else {
			// #ifdef APP
			this.getOrderListData();
			// #endif

		}

	},
	methods: {
		printTitle(e){
			uni.showModal({
				title: '确认打印货物标签',
				content: '是否继续操作？',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
						printTool.printTitle(e);
					}
				}
			});
		},
		printOrder(e){
			uni.showModal({
				title: '确认测试打印货物托运单',
				content: '是否继续操作？',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
						printTool.printOrder(e);
					}
				}
			});
		},
		
		allowHeaderShow() {
			this.isHeaderShow = !this.isHeaderShow;
		},
		statusConfirm(e) {
			this.statusShow1 = false;
			this.searchData.status = e.value[0].value;
			this.searchData.status_name = e.value[0].text;
		},
		statusConfirm2(e) {
			this.statusShow2 = false;
			this.searchData.status_p2 = e.value[0].value;
			this.searchData.status_p2_name = e.value[0].text;
		},
		statusClose(e) {
			this.statusShow1 = false;
			this.statusShow2 = false;
		},
		statusShowClick(e) {
			if (e == 1) {
				this.statusShow1 = true;
			} else {
				this.statusShow2 = true;
			}
		},
		timeShowClick(e,t){
			if(t == 1){
				this.searchData.createtime_start = e.detail.value;
			}else{
				this.searchData.createtime_end = e.detail.value;
			}
		},
		
		showDepartBtn(item) {
			return listStatus.showDepartBtn(item);
		},
		showDeliveryBtn(item) {
			return listStatus.showDeliveryBtn(item);
		},
		showAllocationBtn(item) {
			return listStatus.showAllocationBtn(item);
		},

		getSelect(row) {
			return listStatus.getSelect(row);
		},
		waybillStatus(rows) {
			return listStatus.status(rows);
		},
		getStatusP2(rows) {
			return listStatus.getStatusP2(rows);
		},
		getLevel(rows) {
			return listStatus.getLevel(rows);
		},
		getStatus(rows) {
			return listStatus.getStatus(rows);
		},
		getTransitStatus(rows) {
			return listStatus.getTransitStatus(rows);
		},
		getDestinationCity(rows) {
			return listStatus.getDestinationCity(rows);
		},
		getDisabledDel(rows) {
			return !listStatus.getDisabledEdit(rows);
		},
		getDisabledEdit(rows) {
			return !listStatus.getDisabledEdit(rows);
		},
		getDepartPic1(rows) {
			return listStatus.getDepartPic1(rows);
		},
		getDepartPic2(rows) {
			return listStatus.getDepartPic2(rows);
		},
		getArrivePic1(rows) {
			return listStatus.getArrivePic1(rows);
		},
		getAllocatePic1(rows) {
			return listStatus.getAllocatePic1(rows);
		},
		getAllocatePic2(rows) {
			return listStatus.getAllocatePic2(rows);
		},
		carLoading(e) {
			this.$util.redirectTo('/pages/order/order-confirm/order-depart-confirm', e, null, 'obj');
		},
		queryClick(){
			this.pagenum = 1;
			this.orderList = [];
			this.getOrderListData();
		},
		resetClick(){
			this.searchData={
				waybill_sn:'',
				status:'',
				status_p2:'',
				createtime_start:'',
				createtime_end:'',
				send_username:'',
				send_mobile:'',
				take_username:'',
				take_mobile:'',
			}
		},
		getStatusTitleShow(e) {//1第一行 2第二行
			let level = uni.getStorageSync(this.preutils.accountLevel);
			if (e == 1) {
				if (level == 2) { //二级账号
					return true;
				}else { //1一级账号 0级账号
					return false;
				}
			} else if (e == 2) { //二级状态
				if (level == 2) { //二级账号
					return false;
				}else { //1一级账号 0级账号
					return true;
				}
			}
		},
		getStatusTitle(e) {
			let level = uni.getStorageSync(this.preutils.accountLevel);
			if (level == 2) { //二级账号
				return '运单状态';
			} else if (level == 1) { //一级账号
				return '运单状态';
			} else { //0级账号
				return '一级运单状态';
			}
		},
		toDetail(item) {
			this.$util.redirectTo('/pages/order/order-detail/order-detail', {
				waybill_id: item.waybill_id,
				in_type: '1',
			});
		},
		toEdit(item) {
			this.$util.redirectTo('/pages/order/order-edit/order-edit', {
				waybill_id: item.waybill_id,
			});
		},
		toDel(item) {
			uni.showModal({
				title: '删除后无法回复',
				content: '是否继续操作？',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
						this.delLoadData(e);
					}
				}
			});
		},
		delLoadData(e) {
			var data = {
				waybill_id: e.waybill_id
			};
			if (this.$refs.loadingCover) this.$refs.loadingCover.show();
			this.http.sendRequest({
				api: this.api.order.waybillDelete,
				data: data,
				success: res => {
					let msg = res.message;
					if (res.code == '1') {
						this.$util.showToastSuc('删除成功');
						this.pagenum = 1;
						this.getOrderListData();
					} else {
						this.$util.showToast({
							title: msg
						});
					}
				},
				fail: res => {
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
		/*下拉刷新的回调 */
		downCallback() {
			this.pagenum = 1;
			// this.pagesize = 10;
			this.mescroll.resetUpScroll();
		},
		/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
		upCallback(page) {
			this.pagenum = page.num;
			this.pagesize = page.size;
			this.getOrderListData();
		},
		//点击空布局按钮的回调
		emptyClick() {
			this.$util.redirectTo('/pages/index/index/index', {}, 'redirectTo');
		},

		getOrderListData(type) {
			if (!this.check.isLogin()) {
				return
			}
			this.getWaybillListData();
		},
		getWaybillListData(type) {
			var data = {
				page: this.pagenum,
				page_size: this.pagesize,
			};
			 console.log(this.searchData)
			 console.log(this.status_value2)
			if (!this.check.isNull(this.searchData.waybill_sn, '')) {
				data.waybill_sn = this.searchData.waybill_sn;
			}

			if (!this.check.isNull(this.searchData.status, '')) {
				data.status = this.searchData.status;
			}

			 if (!this.check.isNull(this.searchData.status_p2, '')) {
			 	data.status_p2 = this.searchData.status_p2;
			 }

			 if (!this.check.isNull(this.searchData.createtime_start, '')) {
			 	data.createtime_start = this.searchData.createtime_start;
			 }

			 if (!this.check.isNull(this.searchData.createtime_end, '')) {
			 	data.createtime_end = this.searchData.createtime_end;
			 }

			if (!this.check.isNull(this.searchData.send_username, '')) {
				data.send_username = this.searchData.send_username;
			}

			if (!this.check.isNull(this.searchData.send_mobile, '')) {
				data.send_mobile = this.searchData.send_mobile;
			}

			if (!this.check.isNull(this.searchData.take_mobile)) {
				data.keyValue = this.searchData.take_mobile;
			}
			if (!this.check.isNull(this.searchData.take_username)) {
				data.keyValue  = this.searchData.take_username;
			}
			console.log(this.status_value1)
			console.log(this.status_value2)
			if (!this.check.isNull(this.status_value1, '')) {
				data.status = this.status_value1;
			}
			if (!this.check.isNull(this.status_value2, '')) {
				data.status_p2 = this.status_value2;
			}
  
			this.emptyShow = false;
			// if (this.$refs.loadingCover) this.$refs.loadingCover.show();
			this.http.sendRequest({
				api: this.api.order.waybllListApi,
				data: data,
				success: res => {
					this.emptyShow = true;
					this.emptyType = 'order';
					let newArr = [];
					let msg = res.message;
					if (res.code == '1' && res.data) {
						newArr = res.data.data;
					} else {
						this.$util.showToast({
							title: msg
						});
					}
					console.log(res)
					this.mescroll.endSuccess(newArr.length);
					//设置列表数据
					if (this.pagenum == 1) this.orderList = []; //如果是第一页需手动制空列表
					this.orderList = this.orderList.concat(newArr); //追加新数据
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					this.emptyType = 'order';
					this.emptyShow = true;
					this.mescroll.endSuccess();
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},

		allocationListLoadData(e) {
			var data = {
				status: '500',
				page: this.pagenum,
				page_size: this.pagesize,
			};
			// console.log(this.check.isLogin())
			this.emptyShow = false;
			this.http.sendRequest({
				api: this.api.order.allocationList,
				data: data,
				success: res => {
					this.emptyShow = true;
					this.emptyType = 'order';
					let newArr = [];
					let msg = res.message;
					if (res.code == '1' && res.data) {
						newArr = res.data.data;
					} else {
						this.$util.showToast({
							title: msg
						});
					}
					console.log(res)
					this.mescroll.endSuccess(newArr.length);
					//设置列表数据
					if (this.pagenum == 1) this.orderList = []; //如果是第一页需手动制空列表
					this.orderList = this.orderList.concat(newArr); //追加新数据
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					this.emptyType = 'order';
					this.emptyShow = true;
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
	}
};